﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using wUniApp.MVC.App_Data;

namespace wUniApp.MVC.Controllers
{
  public class ExecutionsController : wBaseController<Execution>
  {

    // GET: Executions
    public override ActionResult Index()
    {
      var executions = dbc.Executions.Include(e => e.Customer);
      return View(executions.ToList());
    }


    // GET: Executions/Create
    public override ActionResult Create()
    {
      ViewBag.CustomerId = new SelectList(dbc.Customers, "Id", "FirstName");
      return base.Create();
    }

    // POST: Executions/Create
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public override ActionResult Create([Bind(Include = "Id,Description,CustomerId,AmountDue")] Execution execution)
    {
      if (ModelState.IsValid)
      {
        dbc.Executions.Add(execution);
        dbc.SaveChanges();
        return RedirectToAction("Index");
      }

      ViewBag.CustomerId = new SelectList(dbc.Customers, "Id", "FirstName", execution.CustomerId);
      return View(execution);
    }

    // GET: Executions/Edit/5
    public override ActionResult Edit(int? id)
    {
      if (id == null)
      {
        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
      }
      Execution execution = dbc.Executions.Find(id);
      if (execution == null)
      {
        return HttpNotFound();
      }
      ViewBag.CustomerId = new SelectList(dbc.Customers, "Id", "FirstName", execution.CustomerId);
      return View(execution);
    }

    // POST: Executions/Edit/5
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public override ActionResult Edit([Bind(Include = "Id,Description,CustomerId,AmountDue")] Execution execution)
    {
      if (ModelState.IsValid)
      {
        dbc.Entry(execution).State = EntityState.Modified;
        dbc.SaveChanges();
        return RedirectToAction("Index");
      }
      ViewBag.CustomerId = new SelectList(dbc.Customers, "Id", "FirstName", execution.CustomerId);
      return View(execution);
    }

  }
}